package xj.graph2d.template.uml;

import xj.graph2d.AbstractModelListener;
import xj.graph2d.DrawShape;
import xj.graph2d.DrawShapeConstants;
import xj.graph2d.GraphNodeBase;
import xj.graph2d.shapes.uml.UMLUtil;
import xj.model.uml.Actor;

public class UMLActorModelListener extends AbstractModelListener {

  public UMLActorModelListener() {
  }

  public UMLActorModelListener(Object model, DrawShape shape) {
    super(model, shape);
  }

  @Override
  public void updateModel() {
    if (shape instanceof GraphNodeBase && model instanceof Actor) {
      GraphNodeBase anode = (GraphNodeBase) shape;
      Actor amodel = (Actor) model;
      String name = UMLUtil.getName(anode, DrawShapeConstants.ROLE_NODE_LABEL);
      String st = UMLUtil.getStereotypes(anode,
	  DrawShapeConstants.ROLE_NODE_LABEL);
      if (name != null) {
	amodel.setName(name);
      }
      amodel.setStereotypes(st);
    }
  }

  @Override
  public void updateShape() {
    if (shape instanceof GraphNodeBase && model instanceof Actor) {
      GraphNodeBase anode = (GraphNodeBase) shape;
      Actor amodel = (Actor) model;
      String name = amodel.getName();
      String st = amodel.getStereotypeString();
      UMLUtil.setName(anode, DrawShapeConstants.ROLE_NODE_LABEL, name);
      // anode.setLabel(name);
      UMLUtil.setStereotypes(anode, DrawShapeConstants.ROLE_NODE_LABEL, st);
    }
  }

}
